<%--
  Created by IntelliJ IDEA.
  User: liyong
  Date: 2010-9-1
  Time: 17:57:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/pages/inc/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="decorator" content="default.index">
    <script type="text/javascript" src="/js/checkModifyAccount.js"></script>
    <style type="text/css">
        .tips-warning {
            display: none;
            float: left;
            margin-left: 5px;
        }
    </style>
    <script type="text/javascript">

        $(function() {
            $('#userName').focus(function() {
                $(this).css("border", "2px solid #A0BDC9");
                $(this).next(".tips-warning").css("display", "block");
                $("#resultUserName").html("").removeClass("tips-error");
            }).blur(function() {
                $(this).css("border", "1px solid #A0BDC9");
                $(this).next(".tips-warning").css("display", "none");
                var userName = $("#userName").val();
                var userStr = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

                //                if (userName == "") {
                //                    $("#resultUserName").addClass("tips-error").html("电子邮件不能为空");
                //                    return false;
                //                }
                if (userName.length > 0) {
                    if (!userStr.test(userName)) {
                        $("#resultUserName").addClass("tips-error").html("电子邮件格式有误，请重新输入！");
                        return false;
                    }
                    if (userName.length > 50) {
                        $("#resultUserName").addClass("tips-error").html("长度不能超过50");
                        return false;
                    } else {
                        $("#resultUserName").removeClass("tips-error").html("");
                        $.getJSON("${ctx}/adPublisher/checkUser.aspx?rand=" + Math.random(), {'userId':userName}, function showData(data) {
                            if (data.result == 'success') {
                                $("#resultUserName").addClass("tips-error").html("该账户已经存在");
                            }
                        })
                    }
                }
            });

            $("#modifyAccount").click(function() {
                var userStr = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
                var userName = $("#userName").val();
                if (userName == "") {
                    $("#resultUserName").addClass("tips-explain tips-error").css('display', 'block').html("电子邮件不能为空");
                    return false;
                }

                if (!userStr.test(userName)) {
                    $("#resultUserName").addClass("tips-explain tips-error").css('display', 'block').html("电子邮件格式有误，请重新输入！");
                    return false;
                }
                if (userName.length > 50) {
                    $("#resultUserName").addClass("tips-explain tips-error").css('display', 'block').html("长度不能超过50");
                    return false;
                }

                var password = $("#password").val();
                if (password == "") {
                    $("#resultPassword").addClass("tips-explain tips-error").css('display', 'block').html("密码不能为空");
                    return false;
                }

                $.ajax({
                    type: "POST",
                    url: "${ctx}/account/modifypartnername.aspx",
                    data: "userName=" + userName + "&password=" + password,
                    dataType:"json",
                    success: function(msg) {
                        if (msg.result == "errorPassword") {
                            $("#resultPassword").addClass("tips-explain tips-error").css('display', 'block').html("您输入的密码错误");
                        } else {
                            $(".popbg").css("height", $(document).height() + "px").css("width", document.documentElement.scrollWidth + "px").show();
                            $(".pop-content").css("left", $(document).width() / 2 - $('.pop-content').width() / 2 - 18 + "px");
                            $('.pop-content').show();
                        }
                    }
                });
            })
        })
    </script>
</head>

<body>

<div class="rightblock">
    <h3>修改用户账号</h3>

    <div class="allfield"><label><span>* 项表示必填选项</span></label></div>
    <div class="allfield"><label>修改的用户帐号：</label>
        <input type="text"
               class="input-text" id="userName"
               value=""
               name="userName"/>

        <div class="tips-warning">请输入邮箱</div>
        <span id="resultUserName"></span>
    </div>
    <div class="allfield"><label>请输入用户密码：</label>
        <input type="password" class="input-text"
               id="password"
               name="password"/>

        <div class="tips-explain tips-warning">请输入用户密码</div>
        <span id="resultPassword"></span>
    </div>
    <div class="allfield sbm-button"><label>&nbsp;</label><span class="btn-right" style="width:60px;">
                <input type="button" value="保存" class="btn" style="width:60px;" id="modifyAccount"/></span>
        <%--<label style="width:50px;">&nbsp;</label>--%>
        <%--<span class="cl-btn-right"><input type="button" value="返回" class="cl-btn"--%>
        <%--style="width:60px;" onclick="history.back();"/></span>--%>
        &nbsp;&nbsp;<a href="javascript:" onclick="history.back()">返回</a>
    </div>
</div>
</body>
</html>